package terra.network.packet.server;

import org.jboss.netty.buffer.ChannelBuffer;

import terra.network.packet.Packet;


public class WaterInfo extends Packet {
	public static final int size = 32;

	public int[] coordsx;//2*256
	public int[] coordsy;//2*256
	public float[] masses; //4*256

	public WaterInfo() {
	}

	public void init(int length){
		coordsx = new int[length];
		coordsy = new int[length];
		masses = new float[length];
	}
	
	@Override
	public ChannelBuffer toBuffer() {
		ChannelBuffer buf = getNewBuffer(1+4+coordsx.length*4*3);
		buf.writeByte(getId());
		buf.writeInt(coordsx.length*4*3);
		for(int i = 0; i < coordsx.length;i++) {
			buf.writeInt(coordsx[i]);
			buf.writeInt(coordsy[i]);
			buf.writeFloat(masses[i]);
		}
		return buf;
	}

	@Override
	public Packet fromBuffer(ChannelBuffer buf) {
		int length = buf.readInt(); 
		init(length/12);
		for(int i = 0; i < length/12;i++) {
			coordsx[i] = buf.readInt();	
			coordsy[i] = buf.readInt();	
			masses[i] = buf.readFloat();	
		}
		return this;
	}

	@Override
	public int getLength() {
		return 0;
	}

	@Override
	public boolean isDynamicLength() {
		return true;
	}

	@Override
	public byte getId() {
		return 30;
	}
	
	@Override
	public byte getPriority() {
		return PRIOR_LOW;
	}
	
}
